import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
// import path from 'node:path';


export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1725275092934_6902';


  // add your egg config in here
  config.middleware = ['compress'];

  config.mysql = {
    client: {
      // 域名/IP
      host: 'localhost',
      // 端口
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: 'Wanglizhi2$',
      // 数据库
      database: 'metaverse',
    },
  };


  // 文件上传格式
  // exports.multipart = {
  //   mode: 'file', // 使用stream模式处理文件上传
  //   fileSize: '200mb', // 设置文件大小限制
  //   whitelist: [
  //     '.*',
  //   ],
  // };
  config.multipart = {
    mode: 'file',
    fileSize: '50mb',
    whitelist: ['.obj', '.mp4', '.jpg', '.png', '.jpeg'],
  };
  // csrf
  config.security = {
    csrf: {
      enable: false,
    },
    domainWhiteList: ['*'],
  };
  config.cors = {
    origin: '*',
    allowMethods: 'GET, HEAD, PUT, POST, DELETE, PATCH',
  };


  // 压缩中间件配置
  config.compress = {
    // 启用 compression 中间件
    enable: true,
    // 设置压缩级别，范围为 0-9，0 表示不压缩，9 表示最大压缩
    level: 6,
    // 只压缩大于该大小的响应体，单位是字节
    threshold: 2048, // 默认值是 1KB
    // 可以添加其他选项，比如:
    gzip: true, // 启用 gzip
    // deflate: true, // 启用 deflate
    // br: true // 启用 Brotli

  };


  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  const jwt = {
    secret: 'metaverse_manager_secret',
  };


  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
    jwt,
  };
};
